package com.audaque.springboot.foshanupload.web.springsecuritycas.config;

import com.audaque.springboot.foshanupload.web.springsecuritycas.handler.UrlAuthenticationSuccessHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.cas.ServiceProperties;
import org.springframework.security.cas.web.CasAuthenticationFilter;
import org.springframework.security.config.BeanIds;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.web.authentication.logout.LogoutFilter;
import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler;

/**
 * @author zgb
 * @desc ...
 * @date 2022-12-17 15:37:15
 */
//@Configuration
public class ServiceSecurityCasWebSecurityLogoutFilterConfig {

    @Value("${cas.server.logout}")
    private String casServerLogout;

    @Value("${cas.client.relative}")
    private String casClientLogoutRelative;


    /**
     * 配置CAS登出入口:将客户端登出地址绑定到服务端登出地址，实现客户端登出地址重定向到服务端登出地址
     *
     * @return
     */
    @Bean
    public LogoutFilter requestSingleLogoutFilter() {
        LogoutFilter logoutFilter = new LogoutFilter(casServerLogout, new SecurityContextLogoutHandler());
        // 将客户端登出地址绑定到服务端登出地址
        logoutFilter.setFilterProcessesUrl(casClientLogoutRelative);
        return logoutFilter;
    }

}
